package ihm.views.equip;

import ihm.views.options.ATKjOptionPane;
import equipments.Items;
import equipments.enumeration.EquipmentSlots;
import java.util.LinkedList;

import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

import systems.languages.MultiLanguages;

public class EquipBox
{

  public static boolean displayReplaceItem(EquipmentSlots slot, Items newItem, Items oldItem)
  {
    String newItemName = newItem.getName();
    String oldItemName = oldItem.getName();
    int response ;
    String templateString =  MultiLanguages.getProperties("dialog.ReplaceItem.text");
    templateString = templateString.replaceAll("\\$old", oldItemName);
    templateString = templateString.replaceAll("\\$new", newItemName);
    templateString = templateString.replaceAll("\\$n ", "\n");
    templateString = templateString.replaceAll("\\$t ", "\t");
    //Display the DialogBox
    response = ATKjOptionPane.showConfirmDialog(null,
        templateString,
        MultiLanguages.getProperties("dialog.ReplaceItem.title"),
        JOptionPane.YES_NO_OPTION,
        JOptionPane.QUESTION_MESSAGE,
        new ImageIcon(MultiLanguages.getProperties("dialog.ReplaceItem.icon")) //icon
    );
    //Treat the response
    if(response == 0)
      return true;
    return false;
  }

  public static EquipmentSlots displaySlotsSelector(LinkedList<EquipmentSlots> slotsList)
  {
    String slotNameSelected;
    EquipmentSlots slotSelected = null;
    String[] slotLabelList = new String[slotsList.size()];
    int tmpIndex = 0;

    for(EquipmentSlots slot : slotsList)
      slotLabelList[tmpIndex++] = (tmpIndex-1)+" - "+slot.toString(slot);

    slotNameSelected = (String)ATKjOptionPane.showInputDialog(null,
        MultiLanguages.getProperties("dialog.SelectSlot.text"),
        MultiLanguages.getProperties("dialog.SelectSlot.title"),
        JOptionPane.PLAIN_MESSAGE,
        null,
        slotLabelList,
        slotLabelList[0]);

    if(slotNameSelected != "null")
      slotSelected = slotsList.get(Integer.valueOf(slotNameSelected.split(" - ")[0]));
    
    return slotSelected;
  }

}
